import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:sui_shou_pai/module/effect.dart';

import '../data/news_list_item_data.dart';
import 'news_detail.dart';

Widget initNewsListItem(BuildContext context, NewsListItemData item) {
  return GestureDetector(
    onTap: () {
      Navigator.push(context,
          MaterialPageRoute(builder: (context) => NewsDetail(item: item)));
    },
    child: Container(
      margin: EdgeInsets.fromLTRB(12, 12, 12, 0),
      padding: EdgeInsets.all(12),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: borderRadiusAll8(),
        boxShadow: [shadowOffsetY2()],
      ),
      child: Row(
        children: <Widget>[
          initNewsText(item.title, item.time, item.source),
          initNewsImage(item.headerImagePath)
        ],
      ),
    ),
  );
}

Widget initNewsText(String title, String time, String source) {
  return Expanded(
      child: Container(
    height: 100,
    padding: EdgeInsets.only(right: 12),
    child: Column(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        initNewsTitle(title),
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            initNewsTimeSource(time, source),
            // initNewsLikeComment(likeCount, commentCount)
          ],
        )
      ],
    ),
  ));
}

Widget initNewsTitle(String title) {
  return Text(
    title,
    maxLines: 2,
    overflow: TextOverflow.ellipsis,
    style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
  );
}

Widget initNewsTimeSource(String time, String source) {
  return Text(
    '$time  $source',
    style: TextStyle(fontSize: 14, color: Colors.grey),
  );
}

Widget initNewsImage(String headerImagePath) {
  return ClipRRect(
    borderRadius: borderRadiusAll4(),
    child: Image.asset(headerImagePath,
        height: 100, width: 140, fit: BoxFit.cover),
  );
}
